#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author: Mapanqi
# 广度遍历核心是
# 深度遍历核心是

class Node(object):
    def __init__(self, value=None, lchild=None, rchild=None):
        self.value = value
        self.lchild = lchild
        self.rchild = rchild


# 前序遍历
def pre_order(root):
    if not root:
        return None
    print(root.value)
    pre_order(root.lchild)
    pre_order(root.rchild)


def mid_order(self, root):
    if not root:
        return None
    mid_order(root.lchild)


def wide_order(root):
    """利用队列实现树的层次遍历"""
    if root == None:
        return
    queue = []
    queue.append(root)
    while queue:
        node = queue.pop(0)
        print(node.value)
        if node.lchild != None:
            queue.append(node.lchild)
        if node.rchild != None:
            queue.append(node.rchild)

if __name__ == "__main__":
    n4 = Node(4)
    n5 = Node(5)
    n6 = Node(6)
    n7 = Node(7)

    n2 = Node(2, n4, n5)
    n3 = Node(3, n6, n7)
    n1 = Node(1, n2, n3)
